﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TaxBusiness.Model;
using TaxBusiness.DAL;

namespace TaxBusiness.BLL
{
    public class UserBLL
    {
        public Model.Users CheckLogin(string username)
        {
            DAL.UsersDB userdb = new UsersDB();
            Model.Users user = new Users();
            user = userdb.Get(username);
            return user;
        }

        public List<Users> GetAll()
        {
            UsersDB userdb = new UsersDB();
            List<Users> usersList = new List<Users>();
            usersList = userdb.GetAll();
            return usersList;
        }

        public int Save(Model.Users users, string menuids)
        {
            DAL.UsersDB userdb = new UsersDB();
            string[] menu = menuids.Split(',');
            int[] menuItem = Array.ConvertAll(menu, s => int.Parse(s));
            return userdb.Insert(users, menuItem);
        }

        public int update(Users users, string menuids)
        {
            DAL.UsersDB userdb = new UsersDB();
            string[] menu = menuids.Split(',');
            int[] menuItem = Array.ConvertAll(menu, s => int.Parse(s));
            return userdb.Update(users, menuItem);
        }

        public int SetActivate(string ids, bool isActivate)
        {
            UsersDB userdb = new UsersDB();
            string[] id = ids.Split(',');
            int[] idArray = Array.ConvertAll(id, s => int.Parse(s));
            return userdb.SetActivate(idArray, isActivate);
        }

        public int SetPWD(int id, string pwd)
        {
            UsersDB userdb = new UsersDB();
            return userdb.SetPWD(id, pwd);
        }


        public int Delete(string  ids)
        {
            UsersDB userdb = new UsersDB();
            string[] id = ids.Split(',');
            int[] idArray = Array.ConvertAll(id, s => int.Parse(s));
            return userdb.Delete(idArray);
        }
    }
}
